<div class="layui-card-header">
    <h2 class="header-title">修改密码</h2>
</div>
<div class="layui-card-body" style="padding: 30px;">
    <form class="layui-form" id="form-psw">
        <div class="layui-form-item">
            <input type="password" name="oldPsw" required lay-verify="required" class="layui-input" placeholder="请输入原密码"
                lay-verType="tips">
        </div>
        <div class="layui-form-item">
            <input type="password" name="newPsw" required lay-verify="required" class="layui-input" placeholder="请输入新密码"
                lay-verType="tips">
        </div>
        <div class="layui-form-item">
            <input type="password" name="rePsw" required lay-verify="required|repsw" class="layui-input"
                placeholder="再次输入新密码" lay-verType="tips">
        </div>
        <div class="layui-form-item">
            <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="submit-psw">确认修改</button>
        </div>
    </form>
</div>

<script>
    layui.use(['form', 'admin', 'config'], function () {
        var form = layui.form;
        var admin = layui.admin;
        var config = layui.config;
        var token = config.getToken();
        //监听提交
        form.on('submit(submit-psw)', function (data) {
            layer.load(2);
            admin.req('UpdateAdminPassById', data.field, function (data) {
                if (data.code == 200) {
                    layer.closeAll('loading');
                    admin.closePopupRight();
                    layer.msg(data.msg, { icon: 1 }, function () {
                        // location.href = '/logout';
                    });
                } else {
                    layer.closeAll('loading');
                    layer.msg(data.msg, { icon: 2 });
                }
            }, 'POST');
            return false;
        });

        //添加表单验证方法
        form.verify({
            repsw: function (t) {
                if (t !== $('#form-psw input[name=newPsw]').val()) {
                    return '两次密码输入不一致';
                }
            }
        });
    });
</script>